package com.itheima.day05.homework1;

import java.math.BigDecimal;

/*
有以下double数组：
		double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
	请编程计算它们的总值及平均值(四舍五入保留小数点后2位)
 */
public class Demo1 {
    public static void main(String[] args) {
        double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
            BigDecimal[] bd=new BigDecimal[arr.length];
        BigDecimal sum = BigDecimal.valueOf(0);
        for (int i = 0; i < arr.length; i++) {
            bd[i] = BigDecimal.valueOf(arr[i]);
            sum=sum.add(bd[i]);

        }
        System.out.println(sum);
        BigDecimal avg = sum.divide(BigDecimal.valueOf(arr.length),2);
        System.out.println(avg);


    }
}
